#include "qxreporttablecell.h"
#include <QFontMetrics>

QXReportTableCell::QXReportTableCell(QObject *parent) : QObject(parent)
{
    m_iLeftMargin = 0;
    m_iTopMargin = 0;
    m_iRightMargin = 0;
    m_iBottomMargin = 0;

    m_bAutoMargin = true;

    m_iRowSpan = 1;
    m_iColumnSpan = 1;
}

QString QXReportTableCell::text()
{
    return m_strText;
}

void QXReportTableCell::setText(const QString &text)
{
    m_strText = text;
}

int QXReportTableCell::rowSpan()
{
    return m_iRowSpan;
}

void QXReportTableCell::setRowSpan(int span)
{
    m_iRowSpan = span;
}

int QXReportTableCell::columnSpan()
{
    return m_iColumnSpan;
}

void QXReportTableCell::setColumnSpan(int span)
{
    m_iColumnSpan = span;
}

void QXReportTableCell::setMargins(int iLeftMargin, int iTopMargin, int iRightMargin, int iBottomMargin)
{
    m_iLeftMargin = iLeftMargin;
    m_iTopMargin = iTopMargin;
    m_iRightMargin = iRightMargin;
    m_iBottomMargin = iBottomMargin;
}

bool QXReportTableCell::autoMargin()
{
    return m_bAutoMargin;
}

void QXReportTableCell::setAutoMargin(bool AutoMargin)
{
    m_bAutoMargin = AutoMargin;
}


int QXReportTableCell::leftMargin()
{
    return m_iLeftMargin;
}

int QXReportTableCell::topMargin()
{
    return m_iTopMargin;
}

int QXReportTableCell::rightMargin()
{
    return m_iRightMargin;
}

int QXReportTableCell::bottomMargin()
{
    return m_iBottomMargin;
}

// 自动计算页边距
int QXReportTableCell::getTextMinHight(const QFont &font, int flag, int width)
{
    int contentWidth = width;
    if(leftMargin() > 0)
    {
        contentWidth -= leftMargin();
    }

    if(rightMargin() > 0)
    {
        contentWidth -= rightMargin();
    }

    QFontMetrics fm(font);
    QRect bdRect = fm.boundingRect(0,0,contentWidth, contentWidth*1000,flag, text());

    int height = bdRect.height();
    if(topMargin() > 0)
    {
        height += topMargin();
    }

    if(bottomMargin() > 0)
    {
        height += bottomMargin();
    }

    return height;
}


